<?php
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2017/4/16
 * Time: 14:34
 */

namespace app\home\controller\user;


class Collection extends Common
{
    private $mod;
    public function _initialize()
    {
        parent::_initialize();
        $this->mod = model('collection');
        $this->_name = 'Collection';
    }
    public function index(){
        $where['user_id'] = $this->userInfo['id'];
        $where['type']    = 1;//收藏
        $lists = $this->mod->where($where)->order('id desc')->paginate(10);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
        return $this->fetch();
    }
    public function delete(){
        \app\common\model\Collection::event('after_delete',function($obj){
            $where['id'] = $obj->house_id;
            $field = $obj->type == 1 ? 'collection' : 'love';
            model('house')->where($where)->setDec($field);
        });
        parent::delete();
    }
}